// pages/department/department.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orgId:'',
    orgimg:'',
    orgname:'',
    list:[],
  },
getorg(){
  var that = this
  app.req({
    url: 'orgmini/org/newGetOrgInfo',
    data: {
      orgId: that.data.orgId
    },
    success: function (res) {
      if (200 == res.code) {
        that.toggle("orgimg", res.data.orgUrl);
        that.toggle("orgname", res.data.orgName);
      }
    }
  });
},
getlist(){
  var that = this
  app.req({
    url: 'orgmini/org/newOrgStructure',
    data: {
      orgId: that.data.orgId
    },
    success: function (res) {
      if (200 == res.code) {
        for(var i in res.data.orgStructureListDtos){
          res.data.orgStructureListDtos[i].isAdmin = 0
        }
        that.toggle("list", res.data.orgStructureListDtos);
        console.log('组织架构列表',that.data.list)
      }
    }
  });
},
  check(e){
    var i = e.currentTarget.dataset.index
    var arr = this.data.list
    if(arr[i].isAdmin==0){
      arr[i].isAdmin=1
    }else{
      arr[i].isAdmin =0
    }
    this.setData({
      list:arr
    })
    // console.log('xuanz',arr)
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },
  save(){
    var that = this
    var structureList = []
    for(var j in that.data.list){
      if(that.data.list[j].isAdmin==1){
        structureList.push(that.data.list[j])
      }
    }
    let pages = getCurrentPages(),
    prevPage = pages[pages.length - 2];
    prevPage.setData({
      structureList: structureList
    })
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      orgId: options.id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this
    that.getorg()
    that.getlist()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})